package com.cssw.fyzb.web.controller;

import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.web.dto.CmfVideoHotDefDto;
import com.cssw.fyzb.web.dto.UpdateOperDto;
import com.cssw.fyzb.web.service.CmfVideoHotDefService;
import com.cssw.fyzb.web.util.SplitUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Feng Chen
 */
@ApiModel("上热门定义接口")
@RestController
@RequestMapping("/cmfVideoHotDef")
public class cmfVideoHotDefController {

    @Autowired
    private CmfVideoHotDefService cmfVideoHotDefService;

    @ApiOperation(value = "上热门定义列表", response = AjaxPage.class)
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "string", required = true),
    })
    public AjaxPage list(int page, int limit) {
        Map param = new HashMap<>();
        return cmfVideoHotDefService.list(page, limit, param);
    }

    @ApiOperation(value = "上热门定义列表", response = AjaxPage.class)
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public AjaxData info(Long hotId) {
        return cmfVideoHotDefService.info(hotId);
    }

    @ApiOperation(value = "新增上热门定义", response = AjaxData.class)
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public AjaxData<Object> save(@RequestBody CmfVideoHotDefDto dto) {
        return cmfVideoHotDefService.save(
                dto.getHotValue(),
                dto.getHotName(),
                dto.getPrice(),
                dto.getHotTime(),
                dto.getHotOprName(),
                dto.getHotOprCode(),
                UserContext.getUserId());
    }

    @ApiOperation(value = "修改上热门定义", response = AjaxData.class)
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public AjaxData update(@RequestBody CmfVideoHotDefDto dto) {
        return cmfVideoHotDefService.update(
                dto.getHotId(),
                dto.getHotValue(),
                dto.getHotName(),
                dto.getPrice(),
                dto.getHotTime(),
                dto.getHotOprName(),
                dto.getHotOprCode(),
                UserContext.getUserId());
    }

    @ApiOperation(value = "删除上热门定义", response = AjaxData.class)
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public AjaxData delete(@RequestBody CmfVideoHotDefDto dto) {
        return cmfVideoHotDefService.delete(dto.getHotId(), UserContext.getUserId());
    }

}
